#!/usr/bin/env python
# -*- conding: utf-8 -*-

"""
@Time     : 2024/8/21 22:02
@Author   : liujingmao
@File     : openai-streaming.py
"""

import dotenv
from openai import OpenAI

dotenv.load_dotenv()

client = OpenAI()

stream = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Say this is a test"}],
    stream=True,
)
for chunk in stream:
    if chunk.choices[0].delta.content is not None:
        print(chunk.choices[0].delta.content, end="")
